package com.easy.huiju.controller;

import cn.hutool.core.thread.ExecutorBuilder;
import cn.hutool.core.thread.ThreadUtil;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.FrameGrabber;
import org.bytedeco.javacv.FrameRecorder;

import java.util.concurrent.*;

public class FutureDemo {

    static ExecutorService executorService= Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2);
    static class Task implements Callable<Boolean> {
        public String name;
        private int time;

        public Task(String s, int t) {
            name = s;
            time = t;
        }

        @Override
        public Boolean call() throws Exception {
            for (int i = 0; i < time; ++i) {
                System.out.println("task " + name + " round " + (i + 1));
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println(name
                            + " is interrupted when calculating, will stop...");
                    return false; // 注意这里如果不return的话，线程还会继续执行，所以任务超时后在这里处理结果然后返回
                }
            }
            return true;
        }
    }


    public static void main(String[] args) {
        ExecutorService executor = ExecutorBuilder.create()//
                .setCorePoolSize(1)//
                .setMaxPoolSize(10)//
                .setWorkQueue(new LinkedBlockingQueue<>(100))

                .build();




    }
    public static void handler() throws InterruptedException {
        //打印当前线程名字
        Thread.currentThread().sleep(5000);
        System.out.println("当前执行线程：" + Thread.currentThread().getName());
    }

}